package com.example.myapplication.tack_13.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_13.DetailsActivity;
import com.example.myapplication.tack_13.SetCardActivity;
import com.example.myapplication.tack_13.data.ArrageData;
import com.example.myapplication.tack_13.data.CardData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class CardsAdapter extends RecyclerView.Adapter<CardsAdapter.My> {
    private List<CardData.RowsDTO> list;
    private Context context;
    private View view;

    public CardsAdapter(List<CardData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_13_card,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        holder.address.setText(list.get(position).getAddress());
        holder.name.setText(String.valueOf(list.get(position).getName()));
        holder.tel.setText("电话："+String.valueOf(list.get(position).getTel()));
        holder.birthday.setText(String.valueOf(list.get(position).getBirthday()));
        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = String.valueOf(list.get(position).getId());
                Intent intent = new Intent(context, SetCardActivity.class);
                intent.putExtra(Common.COMMON,id);
                context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView address;
        private TextView name;
        private TextView tel;
        private TextView birthday;
        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            address = view.findViewById(R.id.address);
            name = view.findViewById(R.id.name);
            tel = view.findViewById(R.id.tel);
            birthday = view.findViewById(R.id.birthday);
            line = view.findViewById(R.id.line);
        }
    }
}
